//
//  ShowFirstViewController.m
//  WuliHanhan
//
//  Created by tang on 16/3/9.
//  Copyright © 2016年 LVpeng. All rights reserved.
//

#import "ShowFirstViewController.h"


#import "FirstVCTableViewCell.h"
#import "CustomNavgation.h"
#import "Header.h"
@interface ShowFirstViewController ()<UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate>{
    
    CustomNavgation *_customNavView;
    float lastContentOffset;
}

@property (nonatomic, strong) UITableView *mainTableView;

@property (nonatomic,strong)UIView *topView;

@end

@implementation ShowFirstViewController


- (void)loadView
{
    [super loadView];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self.navigationController setNavigationBarHidden:YES];
    
    
    _mainTableView = [[UITableView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:_mainTableView];
    
    
    self.automaticallyAdjustsScrollViewInsets = false;
    
    _customNavView = [[CustomNavgation alloc] init];
    
    [self.view addSubview:_customNavView];
    
    _topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 20)];
    [self.view addSubview:_topView];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [_mainTableView setDelegate:self];
    [_mainTableView setDataSource:self];
    // Custom Nav Respond Event
    
    [_customNavView addView];
    
//    [_topView setBackgroundColor:[UIColor colorWithRed:253/255.0 green:202/255.0 blue:47/255.0 alpha:1]];
    [_topView setBackgroundColor:uicolor(253, 202, 47)];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// CustomDelgate Respond Event

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 20;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellInden = @"cell";
    FirstVCTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellInden];
    if (!cell) {
        cell = [[FirstVCTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellInden];
    }
    
    return cell;
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    lastContentOffset = scrollView.contentOffset.y;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (lastContentOffset < scrollView.contentOffset.y && scrollView.contentOffset.y > 64) {
        [UIView animateWithDuration:0.5 animations:^{
            CGRect frame;
            frame = _customNavView.frame;
            CGFloat delta = frame.origin.y + 44;
            frame.origin.y = MAX(-100, frame.origin.y - delta);
            _customNavView.frame = frame;
            _customNavView.alpha = 0;
        }];
    }else{
        [UIView animateWithDuration:0.5 animations:^{
            CGRect frame;
            frame = _customNavView.frame;
            CGFloat delta = frame.origin.y - 44;
            frame.origin.y = MIN(0, frame.origin.y - delta);
            _customNavView.frame = frame;
            _customNavView.alpha = 1.0;
        }];
    }
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
